/**
 * @name 权限
 */
layui.define(['larry', 'form', 'table'], function(exports) {
    "use strict";
    var $ = layui.$,
        larry = layui.larry,
        form = layui.form,
        table = layui.table;
    var tableIns = table.render({
        elem: '#roleList', //指定原始表格元素选择器（推荐id选择器）
        cols: [
        		[{
				field: 'roleId',
				align:'center',
				title: 'ID',
				sort: true,
			}, {
				field: 'name',
				align:'center',
				title: '角色名称',
				align: 'center',
			}, {
				field: 'title',
				align:'center',
				title: '角色标题',
				align: 'center',
			}, {
				field: 'description',
				align:'center',
				title: '角色描述',
				align: 'center',
			}, {
				field: 'orders',
				align:'center',
				title: '排序',
				sort: true,
				align: 'center',
			}, {
				align:'center',
				title: '操作',
				toolbar: '#roleBar'
			}]
        ], //设置表头
        url: '/backend/system/upms/role/findPagingQuery',
        page: true,
		loading: true,
		limits: [10,30,60,90,150,300],
		limit: 10 //默认采用60
    });
    //添加角色
    $('#addRole').on('click', function() {
        layer.open({
            type: 2,
            title: '添加角色',
            shadeClose: true,
            shade: 0.8,
            area: ['100%', '100%'],
            content: '/backend/system/upms/role/add', //iframe的url
            end: function() {
                tableIns.reload();
            }
        });
    });
    
    //监听工具条
    table.on('tool(roleList)', function(obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
           
        } else if (obj.event === 'del') {
        	 	//删除        
            layer.confirm('真的删除行么', function(index) {
                $.post("/backend/system/upms/role/delectRole", {
                    "roleId": data.roleId
                }, function(result) {
                    if (result.status == 200) {
                        tableIns.reload();
                    } else {
                        layer.msg(result.msg);
                        tableIns.reload();
                    }
                    layer.close(index);
                });
            });
        } else if (obj.event === 'edit') {
        		layer.open({
                type: 2,
                title: '添加角色',
                shadeClose: true,
                shade: 0.8,
                area: ['100%', '100%'],
                content: '/backend/system/upms/role/setting?roleId='+data.roleId, //iframe的url
                end: function() {
                    tableIns.reload();
                }
            });
        	
        	
        }
    });
    exports('mypanel', {});
});